package ding;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FileMapping {


    public static Map<String, String> map(File x2X, File nr) {

        try {

            BufferedReader bufferedReader = new BufferedReader(new FileReader(nr));

            List<String> nl = new ArrayList<>();

            String line;

            while ((line = bufferedReader.readLine()) != null) {
                nl.add(line.trim());
            }

            bufferedReader.close();


            Map<String, String> r = new HashMap<>();

            bufferedReader = new BufferedReader(new FileReader(x2X));

            while ((line = bufferedReader.readLine()) != null) {

                String[] split = line.split("->");

                String source = split[0].trim();

                String target = split[1].trim();

                if (nl.contains(target)) {
                    r.put(target, source);
                }


            }

            return r;

        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }


}
